package com.zkingsoft.web.action;

import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.PaginationVO;
import com.zkingsoft.common.service.SysUsersService;
import com.zkingsoft.web.bean.BizNsy;
import com.zkingsoft.web.bean.BizXefCertificate;
import com.zkingsoft.web.bean.WebMsg;
import com.zkingsoft.web.dao.BizNsyDao;
import com.zkingsoft.web.dao.BizXefCertificateDao;
import com.zkingsoft.web.service.WebMsgService;
import com.zkingsoft.web.tool.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 
 * @Description: 不需要登录可以访问的action
 * @author:姜友瑶
 * @date 2016年8月31日
 */
@CrossOrigin("*")
@Controller
public class Home {

	@Autowired
	WebMsgService service;

	@Autowired
	SysUsersService userService;

	@Autowired
	private BizXefCertificateDao bizXefCertificateDao;

	@Autowired
	private BizNsyDao bizNsyDao;

	/**
	 * @Description: 首页配置
	 * @author:姜友瑶
	 * @return 返回类型 String
	 * @date 2016年8月28日
	 */
	@RequestMapping(value = "/home")
	public String index(HttpServletRequest request) {
		String url = "";
		if (Tools.isMoblie(request)) {
			url = "/visitor/" + Tools.getCompanyCode() + "/mobile/index";
		} else {
			url = "/visitor/" + Tools.getCompanyCode() + "/pc/index";
		}
		return url;

	}

	@RequestMapping(value = "/redirect/{page1}")
	public String index(@PathVariable("page1") String page1) {
 
		return "/visitor/" + Tools.getCompanyCode() +"/" + page1;
	}

	@RequestMapping(value = "/redirect/{page1}/{page2}")
	public String redirect(@PathVariable("page1") String page1, @PathVariable("page2") String page2) {
		return "visitor/" + Tools.getCompanyCode() +"/" + page1 + "/" + page2;
	}

	@RequestMapping(value = "/visitor/addMsg")
	public @ResponseBody AjaxResult addMsg(WebMsg msg) {
		msg.setCompanyId(Tools.getCompanyId());
		msg.setCreateTime(new Date());
		service.add(msg);
		return new AjaxResult(AjaxResult.STATUS_SUCCESS, "提交成功");
	}

	/**
	 * 查询sku图片
	 * @author JIANGYOUYAO
	 * @email 935090232@qq.com
	 * @date 2018年12月20日
	 * @param sku
	 * @return
	 */
	@RequestMapping(value = "/visitor/findSku")
	public @ResponseBody AjaxResult findSku(String sku) {

		return new AjaxResult(AjaxResult.STATUS_SUCCESS, "提交成功");
	}


	/**
	 * 网页查询证书
	 * @return
	 */
	@RequestMapping(value = "/queryCertificateByNameOrCode",method = RequestMethod.GET)
	@CrossOrigin("*")
	public @ResponseBody AjaxResult queryCertificateByNameOrCode(String condition){
		List<BizXefCertificate> bizXefCertificate = bizXefCertificateDao.selectByNameOrCode(condition, condition);
		AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS,"");
		result.setRows(bizXefCertificate);
		return result;
	}

	/**
	 * 网页内审员查询
	 * @return
	 */
	@RequestMapping(value = "/queryNsyByNameOrCode",method = RequestMethod.GET)
	@CrossOrigin
	public @ResponseBody AjaxResult queryNsyByNameOrCode(String condition){
		BizNsy bizNsy = bizNsyDao.selectByCodeAndName(condition);
		AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS,"");
		result.putInMap("orgInfo",bizNsy);
		return result;
	}

	@RequestMapping(value = "/queryCertificateList",method = RequestMethod.GET)
	@CrossOrigin
	public @ResponseBody AjaxResult queryCertificateList(String status, PaginationVO pageVo) {
		BizXefCertificate bizXefCertificate = new BizXefCertificate();
		bizXefCertificate.setXcStatus(status);

		pageVo.setOrder("desc");
		pageVo.setSort("create_time");
		List<BizXefCertificate> bizXefCertificates = bizXefCertificateDao.selectInPage(bizXefCertificate, pageVo);

		AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS,"获取成功");
		result.setRows(bizXefCertificates);
		return result;
	}

}